package com.system.neural.service.impl;

import com.system.neural.service.ParseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * ClassName: ParseServiceImpl
 * FileName: ParseServiceImpl.java
 * Description: 情感解析
 * History:
 * 版本号 			作者 			日期       				简介
 * 1.0				znlccy		    2021/10/6 10:07		    create
 */
@Slf4j
@Service
public class ParseServiceImpl implements ParseService {

    /**
     * 执行情感分析
     * @param comment
     */
    @Override
    public void parseComment(String comment) throws Exception{
        try {
            String[] args1 = new String[] { "python", "E:\\javaProject\\System-development\\Code-Resource\\Python-Code\\zcmall\\emotionAnalysis.py", comment};
            Process pr = Runtime.getRuntime().exec(args1);
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    pr.getInputStream(), "gbk"));
            String line;
            while ((line = in.readLine()) != null) {
                log.info("执行结果数据:{}", line);
            }
            in.close();
            pr.waitFor();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
